package com.hhsj.dynamicui.model;


import com.google.gson.annotations.SerializedName;
import com.hhsj.dynamicui.model.base.JSONAble;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.List;

/**
 * 一个页面的视图树结构
 */

public final class UIModule implements Serializable, JSONAble {

    @SerializedName("page_code")
    private String pageCode;
    @SerializedName("page_name")
    private String pageName;
    @SerializedName("page_desc")
    private String pageDesc;
    @SerializedName("page_status")
    private String pageStatus;

    @SerializedName("body_code")
    private String bodyCode;

    private ViewBean property;

    @SerializedName("app_bar")
    private AppBarBean appBar;

    @SerializedName("float_bar")
    private FloatBarBean floatBar;

    @SerializedName("group_list")
    private List<GroupModel> groupList;

    public AppBarBean getAppBar() {
        return appBar;
    }

    public void setAppBar(AppBarBean appBar) {
        this.appBar = appBar;
    }

    public FloatBarBean getFloatBar() {
        return floatBar;
    }

    public void setFloatBar(FloatBarBean floatBar) {
        this.floatBar = floatBar;
    }

    public String getBodyCode() {
        return bodyCode;
    }

    public void setBodyCode(String bodyCode) {
        this.bodyCode = bodyCode;
    }

    public ViewBean getProperty() {
        return property;
    }

    public void setProperty(ViewBean property) {
        this.property = property;
    }

    public List<GroupModel> getGroupList() {
        return groupList;
    }

    public void setGroupList(List<GroupModel> groupList) {
        this.groupList = groupList;
    }

    public String getPageName() {
        return pageName;
    }

    public void setPageName(String pageName) {
        this.pageName = pageName;
    }

    public String getPageCode() {
        return pageCode;
    }

    public void setPageCode(String pageCode) {
        this.pageCode = pageCode;
    }

    public String getPageDesc() {
        return pageDesc;
    }

    public void setPageDesc(String pageDesc) {
        this.pageDesc = pageDesc;
    }

    public String getPageStatus() {
        return pageStatus;
    }

    public void setPageStatus(String pageStatus) {
        this.pageStatus = pageStatus;
    }

    @Override
    public String toJSONString() {
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("page_code", pageCode);
        jsonObject.put("page_name", pageName);
        jsonObject.put("page_desc", pageDesc);
        jsonObject.put("page_status", pageStatus);
        jsonObject.put("body_code", bodyCode);
        if (appBar != null) {
            jsonObject.put("app_bar", appBar);
        }
        if (floatBar != null) {
            jsonObject.put("float_bar", floatBar);
        }

        if (groupList != null && groupList.size() > 0) {
            JSONArray array = new JSONArray();

            for (int i = 0, size = groupList.size(); i < size; i++) {
                JSONObject object = new JSONObject(groupList.get(i).toJSONString());
                array.put(object);
            }

            jsonObject.put("group_list", array);
        }

        if (property != null) {
            jsonObject.put("property", new JSONObject(property.toJSONString()));
        }

        return jsonObject.toString();
    }
}
